<?php
/***************************************************************************
 * 
 * Copyright (c) 2010 , Inc. All Rights Reserved
 * $Id$ 
 * 
 **************************************************************************/
 
 
 
/**
 * @file ValidationFloatTest.php
 * @author niulei(niulei@)
 * @date 2010/05/17 18:58:28
 * @version $Revision$ 
 * @brief 
 *  
 **/
require_once 'PHPUnit/Framework/TestCase.php';
require_once 'validate/Validation.php';
require_once 'address/Address.php';

class ValidationOtherSimpleTest extends PHPUnit_Framework_TestCase{

    protected function setUp()
    {			
       sleep(1);
    }
    
    public function testIdnumEmpty(){
    	$arr_rules = array(
    	                    'func' => 'IDNUM',
    	                   );
    	$input = "";
    	$this->assertContains("Empty checked", Validation::check($input,$arr_rules));
    	$input = "342529198309270030";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "23080319530518062X";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "342529198309270031";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "23080319530518061X";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "230803195305180622";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "3425291983092700";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
        
        $arr_rules = array(
    	                    'func' => 'IDNUM',
                            'flag' => 'FLAG_ALLOW_EMPTY',
    	                   );
    	$input = "";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "342529198309270030";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "23080319530518062X";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "342529198309270031";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "23080319530518061X";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "230803195305180622";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "3425291983092700";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
        $input = "123456789012345";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "12345678901234X";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
        $input = "210703850520094";
        $this->assertTrue(Validation::check($input,$arr_rules));
        $input = "210703001389901";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "690234859529232";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
    }
    
    public function testIdnum(){
    	$arr_rules = array(
    	                    'func' => 'IDNUM',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY',
                                           ),
    	                   );
    	$input = "";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "342529198309270030";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "23080319530518062X";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "342529198309270031";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "23080319530518061X";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "230803195305180622";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "3425291983092700";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
    }
    
    public function testEmail(){
    	$arr_rules = array(
    	                    'func' => 'EMAIL',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY',
                                           ),
    	                   );
    	$input = "";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "niulei@";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "@niulei@";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "niulei";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd@";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        $input = "niulei+niulei@%cn";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
        $input = "niulei*niulei@@";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
    }
    
    public function testBirth(){
    	$arr_rules = array(
    	                    'func' => 'BIRTH',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY',
                                           ),
    	                   );
    	$input = "";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "2009-04-15";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "20090415";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "2009-0415";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "200904-15";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "2009-13-15";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "2009-12-32";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "2009-2-29";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "0000-6-12";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "1996-00-12";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "1996-06-00";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "1996-06-31";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "1983-02-29";
        $this->assertContains("Content checked", Validation::check($input,$arr_rules));
        
        $arr_rules = array(
    	                    'func' => 'BIRTH',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY',
                                           ),
                            'min_range' => '2010-08-24',
                            'max_range' => '2010-08-26'
    	                   );
    	$input = "2010-08-25";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	
    	$arr_rules['min_range'] = "2010-08-25";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$arr_rules['min_range'] = "2010-08-20";
    	$arr_rules['max_range'] = "2010-08-23";
    	$this->assertContains("Length checked", Validation::check($input,$arr_rules));
    }

    public function testPhoneno(){
    	$arr_rules = array(
    	                    'func' => 'PHONENO',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY',
                                           ),
    	                   );
    	$input = "";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "13810008958";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "18810008958";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "15710008958";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "15010008958";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "150100089581";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
    	$input = "16010008958";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
    }
    
    public function testAddress1(){
    	$arr_rules = array(
    	                    'func' => 'ADDLEVEL1',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY',
                                           ),
    	                   );
    	$input = "";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "北京";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "北京市";
    	$this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "安徽省";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "台湾省";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    }
    
    public function testAddress2(){
    	$arr_rules = array(
    	                    'func' => 'ADDLEVEL2',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY',
                                           ),
    	                   );
    	$input = "";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "北京北京市";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "北京市北京市";
    	$this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "安徽省合肥市";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "台湾省台北市";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "台湾省XX市";
    	$this->assertContains("Content checked", Validation::check($input,$arr_rules));
    }

    public function testAddress3(){
    	$arr_rules = array(
    	                    'func' => 'ADDLEVEL3',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY',
                                           ),
    	                   );
    	$input = "";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "北京北京市海淀区";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "北京北京市延庆区";
    	$this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "安徽省合肥市XX区";
    	$this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "台湾省台北市";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "海外海外";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    }
    
    public function testAddress(){
    	$arr_rules = array(
    	                    'func' => 'ADDRESS',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY',
                                           ),
    	                   );
    	$input = "";
    	$this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = "北京北京市海淀区";
    	$this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = array('provinc'=>'北京','city'=>'北京市','country'=>'东城区');
    	$this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = array('province'=>'北京','city'=>'北京市','country'=>'东城区');
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = array('province'=>'台湾省','city'=>'台北市');
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = array('province'=>'台湾省','country'=>'台北市');
    	$this->assertContains("Content checked", Validation::check($input,$arr_rules));
    	$input = array('province'=>'北京','city'=>'北京市','country'=>'其它区');
    	$this->assertTrue(Validation::check($input,$arr_rules));
    }
 
}
?>
